package kr.hkit.powerjava.chapter10;

import java.util.Arrays;
import java.util.Random;

public class LottoGenerater2 {
	private boolean[] lotto;
	private Random rnd;
	private static final int SIZE = 6;

	public LottoGenerater2() {
		lotto = new boolean[45];
		rnd = new Random();
	}
	
	public void getLottoNums(int cnt){
		for(int i = 0; i < cnt; i++){
			getLottoNum();
		}
	}
	
	public void initLotto(){
		for(int i = 0; i < lotto.length; i++){
			lotto[i] = false;
		}
	}
	
	public void getLottoNum(){
		int num = -1;
		initLotto();
		for (int i = 0; i < SIZE; i++) {
			num = rnd.nextInt(45);
			if (lotto[num]){				//중복 된 값이 존재
				i--;
			}else{
				lotto[num] = true;
			}
		}
		prnLottoNum();
	}
	
	public void prnLottoNum(){
		for (int i = 0; i < lotto.length; i++) {
			if(lotto[i]){
				System.out.printf("%3d", i+1);
			}
		}
		System.out.println();
	}

	@Override
	public String toString() {
		return Arrays.toString(lotto);
	}

	public static void main(String[] args) {
		LottoGenerater2 lotto = new LottoGenerater2();
		lotto.getLottoNums(3);
	}
	
}
